package edu.stu.mall.activity.login

import android.app.Application
import android.util.Log
import androidx.lifecycle.viewModelScope
import com.blankj.utilcode.util.SPUtils
import edu.mall.base.BaseViewModel
import edu.mall.base.SingleLiveEvent
import edu.mall.http.HttpConstants
import edu.stu.mall.repository.Repository
import edu.stu.mall.repository.data.LoginData
import edu.stu.mall.repository.data.ProductCategoryListData
import kotlinx.coroutines.launch

class LoginViewModel(application: Application) : BaseViewModel(application) {

    var loginData = SingleLiveEvent<LoginData?>()
    init {
        postLogin()


    }
    private fun postLogin() {
        viewModelScope.launch {
            val data = Repository.postLogin()

            if (data != null) {
                loginData.postValue(data)
                SPUtils.getInstance().put(HttpConstants.SP_TOKEN,data.token)
                Log.e("TAG", "token: ${data.token}", )
            }
        }
    }
}